<?php
if ( function_exists('register_sidebar') ) {
    register_sidebar(array(
	'name'=>'sidebar_full',
        'before_widget' => '<li id="%1$s" class="sidebaritem">',
        'after_widget' => '</div></li>',
        'before_title' => '<h2 class="widgettitle">',
        'after_title' => '</h2><div class="sidebarbox">',
    ));
    register_sidebar(array(
	'name'=>'sidebar_left',
        'before_widget' => '<li id="%1$s" class="sidebaritem">',
        'after_widget' => '</div></li>',
        'before_title' => '<h2 class="widgettitle">',
        'after_title' => '</h2><div class="sidebarbox">',
    ));
    register_sidebar(array(
	'name'=>'sidebar_right',
        'before_widget' => '<li id="%1$s" class="sidebaritem">',
        'after_widget' => '</div></li>',
        'before_title' => '<h2 class="widgettitle">',
        'after_title' => '</h2><div class="sidebarbox">',
    ));
    register_sidebar(array(
	'name'=>'footer_left',
        'before_widget' => '',
        'after_widget' => '',
        'before_title' => '<h3>',
        'after_title' => '</h3>',
    ));

    register_sidebar(array(
	'name'=>'footer_middle',
        'before_widget' => '',
        'after_widget' => '',
        'before_title' => '<h3>',
        'after_title' => '</h3>',
    ));
    register_sidebar(array(
	'name'=>'footer_right',
        'before_widget' => '',
        'after_widget' => '',
        'before_title' => '<h3>',
        'after_title' => '</h3>',
    ));
    register_sidebar(array(
	'name'=>'after_post',
        'before_widget' => '',
        'after_widget' => '',
        'before_title' => '<h3>',
        'after_title' => '</h3>',
    ));
}

add_action('admin_menu', 'add_welcome_interface');

function add_welcome_interface()
{
  add_theme_page('Nehemiah Theme Options', 'Theme Options', '8', 'functions', 'editoptions');
}

function nehemiah_the_tags($before, $seperator, $after) 
{
    $tags = get_the_tags(); 
    $c = 0;
    if ($tags) {
        $first_tag = true;
        foreach ($tags as $tag) {
            if ($tag->count > 1) {
                if ($first_tag) { 
                    $first_tag = false;
                    echo $before;
                } else {
                    echo $seperator;
                }
                echo "<a href=\"". get_tag_link($tag->term_id) ."\" title=\"{$tag->description}\">{$tag->name}</a>";
                $c++;
            }
        }
        if ($c) {
            echo $after;
        }
    }
}

function nehemiah_the_author()
{
    switch (get_option('nehemiah_author_display')) {
        case 'false' :
        break;

        case 'name' :
            echo "by ";
            the_author();
            echo " on ";
        break;

        case 'link':
        default:
            echo "by ";
            the_author_posts_link();
            echo " on ";
    }
}

function editoptions() 
{
  ?>
  <div class='wrap'>
  <h2>Nehemiah Theme Options</h2>
  <form method="post" action="options.php">
  <?php wp_nonce_field('update-options') ?>
  <table class="form-table">

    <tr valign="top">
    <th scope="row">Copyright text</th>
    <td><input type="text" size="100" name="nehemiah_copyright_text" value="<?php echo htmlspecialchars(get_option('nehemiah_copyright_text')); ?>"></td>
    </tr>
    
    <tr valign="top">
    <th scope="row">Display Author</th>
    <td>
    <select name="nehemiah_author_display">
        <?php $selected_array = array('false'=>'','name'=>'', 'link'=>'');
              $selected_array[get_option('nehemiah_author_display')] = ' selected="selected" '; ?>
        <option value="false" <?php echo $selected_array['false']; ?>>Don't display author</option>
        <option value="name" <?php echo $selected_array['name']; ?>>Display name only</option>
        <option value="link" <?php echo $selected_array['link']; ?>>Display name with link to all author's posts</option>
    </select>
    </td>
    </tr>
  </table>

  <p><input type="submit" name="Submit" value="Update Options" /></p>
  <input type="hidden" name="action" value="update" />
  <input type="hidden" name="page_options" value="nehemiah_author_display,nehemiah_copyright_text" />
  </form>
  </div>
  <?php
}

define('DATE_FORMAT', get_option('date_format')); 

?>